package com.hunan.api.catv.action.invite;

import com.hunan.api.catv.action.BaseAction;
import com.hunan.api.catv.annotation.MemberAuth;
import com.hunan.api.catv.common.Api;
import com.hunan.api.catv.entity.Result;
import com.hunan.api.catv.service.biz.invite.MemberInviteBiz;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @Author: wangchao
 * @Date: 2020/11/16 14:08
 */
@RestController
@Validated
@RequestMapping(Api.invite)
public class MemberInviteAction extends BaseAction {

    @Autowired
    MemberInviteBiz memberInviteBiz;

    /**
     * 邀请奖励
     */
    @MemberAuth
    @GetMapping("/getMemberAssetsByInvite")
    public Result getMemberAssetsByInvite(HttpServletRequest request) {
        return buildOK(memberInviteBiz.getMemberAssetsByInvite(getMemberId(request)), "");
    }


    /**
     * 校验是否开启白名单
     */
    @MemberAuth
    @GetMapping("/checkMemberWhitelist")
    public Result checkMemberWhitelist(HttpServletRequest request) {
        return buildOK(memberInviteBiz.checkMemberWhitelist(getMemberId(request)), "");
    }

    /**
     * 不校验token
     */
    @GetMapping("/checkMemberWhitelistByMemberId/{memberId}-{type}")
    public Result checkMemberWhitelistByMemberId(@PathVariable("memberId") Integer memberId, @PathVariable(required = false) String type) {
        return buildOK(memberInviteBiz.checkMemberWhitelist(StringUtils.isEmpty(type) ? memberId : (memberId - 192008)), "");
    }

    /**
     * 邀请记录列表
     */
    @MemberAuth
    @GetMapping(value = {"/getMemberInviteRecord/{pageNum}/{pageSize}","/getMemberInviteRecord/{pageNum}/{pageSize}/{startTime}-{endTime}"})
    public Result getMemberInviteRecord(@PathVariable("pageNum") int pageNum, @PathVariable("pageSize") int pageSize, HttpServletRequest request,@PathVariable(value = "startTime",required = false) String startTime,@PathVariable(value = "endTime",required = false) String endTime) {
        return buildOK(memberInviteBiz.getMemberInviteRecord(pageNum, pageSize, getMemberId(request),startTime,endTime), "");
    }

    /**
     * 校验用户是否签到
     */
    @MemberAuth
    @GetMapping("/checkMemberSign")
    public Result checkMemberSign(HttpServletRequest request) {
        return buildOK(memberInviteBiz.checkMemberSign(getMemberId(request)), "");
    }

}
